//
//  CartTableViewCell.swift
//  iOSProjectExtensionSwift
//
//  Created by HBGG on 2020/7/13.
//  Copyright © 2020 lidianchao. All rights reserved.
//

import UIKit
import Kingfisher
class CartTableViewCell: UITableViewCell {

    var goodsIconImageView = UIImageView()
    var goodsNameLabel = UILabel()
    var modelLabel = UILabel()
    var priceLabel = UILabel()
    var areaLabel = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        configUI()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func configUI() {
        goodsIconImageView = UIImageView(frame: CGRect(x: leftDistance, y: 8, width: 80, height: 72))
        self.contentView.addSubview(goodsIconImageView)
        
        goodsNameLabel = UILabel.createLabel(frame: CGRect(x: goodsIconImageView.maxX+13, y: goodsIconImageView.minY+4, width: 110, height: 13), title: "", textColor: ColorWithHex("#333333"), isCenter: false, font: 14, board: false)
        self.contentView.addSubview(goodsNameLabel)
        
        modelLabel = UILabel.createLabel(frame: CGRect(x: goodsIconImageView.maxX+13, y: goodsNameLabel.maxY+10, width: 110, height: 13), title: "", textColor: ColorWithHex("#333333"), isCenter: false, font: 12, board: false)
        self.contentView.addSubview(modelLabel)
        
        priceLabel = UILabel.createLabel(frame: CGRect(x: goodsIconImageView.maxX+13, y: modelLabel.maxY+20, width: DeviceWidth/2, height: 13), title: "", textColor: ColorWithHex("#e74c3c"), isCenter: false, font: 16, board: true)
        self.contentView.addSubview(priceLabel)
        
        areaLabel = UILabel.createLabel(frame: CGRect(x: priceLabel.viewX, y: priceLabel.viewY, width: DeviceWidth-priceLabel.viewX-leftDistance, height: 13), title: "", textColor: ColorWithHex("999999"), isCenter: false, font: 14, board: false)
        areaLabel.textAlignment = NSTextAlignment.right;
        self.contentView.addSubview(areaLabel)
        
    }
    func setCartGoodsItem(cartGoodsItem:CartGoodsItem) {
        let iamgeUrl = URL(string: cartGoodsItem.iconUrl)
        goodsIconImageView.kf.setImage(with: iamgeUrl)
        goodsNameLabel.text = cartGoodsItem.goodsName
        modelLabel.text = cartGoodsItem.goodsDescript
        priceLabel.text = "¥" + cartGoodsItem.price
        areaLabel.text = cartGoodsItem.areaStr
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
